import ProSwitchButton from '@/components/pro-switch-button/index.vue'
import { Ref } from 'vue'
import { ProFormOptions } from '@/components/pro-form/type'

type props = {
  handleType: Ref<'add' | 'edit' | ''>
}

export const useOrgParamProForm = ({ handleType }: props) => {
  const [orgParamForm, resetOrgParamForm] = useProRef<{ [index: string]: any }>(
    {
      isDefault: false
    }
  )
  const orgParamFormOptions = computed<ProFormOptions>(() => [
    {
      grid: {
        cols: '1'
      },
      columnItemList: [
        {
          formItem: {
            formType: 'select',
            label: '参数类型',
            key: 'type',
            dictCode: 'MD_EMBASSY_PARAM',
            rule: {
              required: true,
              message: '请选择参数类型',
              trigger: ['change']
            },
            disabled: handleType.value === 'edit'
          }
        },
        {
          formItem: {
            formType: 'input',
            label: '参数值',
            key: 'paramValue',
            rule: {
              required: true,
              message: '请输入参数值',
              trigger: ['input']
            },
            placeholder: '请输入参数值'
          }
        },
        {
          formItem: {
            formType: 'custom',
            label: '是否默认',
            key: 'isDefault',
            render() {
              return (
                <ProSwitchButton
                  v-model:value={orgParamForm.value.isDefault}
                  checkedText="默认"
                  uncheckedText="非默认"
                />
              )
            }
          }
        }
      ]
    }
  ])

  return {
    orgParamForm,
    orgParamFormOptions,
    resetOrgParamForm
  }
}
